import * as React from "react";
import { Component } from "react";
import { observer } from "mobx-react";
import { observable } from "mobx";
import { Button } from "antd";

import { DownloadOutlined } from "@ant-design/icons";
import EleAndWater from "../../../../../../compontents/EleAndWater";
import TimeModePicker from "../../../../../../compontents/TimeModePicker";
import "./index.less";

export interface ConditionProps {
  onSubmit: (date: any) => any;
  onDownLoad: (date: any) => any;
}

export interface ConditionState {}

@observer
class Condition extends Component<ConditionProps, ConditionState> {
  @observable public dataJson: any = {};
  // state = { :  }
  render() {
    return (
      <>
        <div className="bare_body" style={{ padding: 16, paddingTop: 0 }}>
          <EleAndWater
            onChange={(type: Number) => {
              this.onEleAndWater(type);
            }}
            style={{ paddingLeft: 16, paddingTop: 16 }}
          />
          <TimeModePicker
            onChange={(date: string, dateString: string) => {
              this.getDate(date, dateString);
            }}
            style={{ paddingTop: 16 }}
          />
          <Button
            type="primary"
            className="l_distance"
            onClick={() => {
              this.getCondition();
            }}
          >
            查询
          </Button>
          <Button
            icon={<DownloadOutlined />}
            className="l_distance"
            onClick={() => {
              this.props.onDownLoad(this.dataJson);
            }}
          >
            导出
          </Button>
          <div className="clear"></div>
        </div>
      </>
    );
  }
  onEleAndWater(type: Number) {
    this.dataJson.type = type;
  }

  getDate(date: string, dateString: string) {
    let num: number = 2;
    switch (date) {
      case "date":
        num = 2;
        break;
      case "month":
        num = 3;
        break;
      case "year":
        num = 4;
        break;
      default:
        break;
    }
    this.dataJson.date = num;
    this.dataJson.dateString = dateString;
  }
  getCondition() {
    this.props.onSubmit(this.dataJson);
  }
}

export default Condition;
